﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Concurrent;
namespace YmtUserAuth.DataImport
{
    public class FillUserContainer
    {
        public static IEnumerable<UserData2> Fill(string filePath)
        {
            var userList = new ConcurrentBag<UserData2>();
            var readResult = ReadFile.SyncRead(filePath);
            foreach (var item in readResult)
            {
                //userList.Add(UserData2.Create((int.Parse(item[0]), item[1], item[2],item[3],item[4]));
                foreach (var userData in UserData2.Create(int.Parse(item[0]), item[1], item[2], item[3], item[4]))
                {
                    userList.Add(userData);
                }
            }
            return userList;
        }

        public static IEnumerable<UserData2> Fill(IEnumerable<string[]> readFileLine)
        {
            var userList = new ConcurrentBag<UserData2>();
            foreach (var item in readFileLine)
            {
                foreach (var userData in UserData2.Create(int.Parse(item[0]), item[1], item[2], item[3], item[4]))
                {
                    userList.Add(userData);
                }
            }
            return userList;
        }

        public static Tuple<Dictionary<string, IEnumerable<UserCredential>>, IEnumerable<UserData>> FillUserData(IEnumerable<string[]> readFileLine)
        {
            var userCredential = new ConcurrentBag<UserCredential>();
            var userCredential2 = new ConcurrentBag<UserCredential>();
            var userList = new ConcurrentBag<UserData>();
            var mappTb = new ConcurrentBag<String>();
            var dic = new Dictionary<string, IEnumerable<UserCredential>>();
            foreach (var item in readFileLine)
            {

                userList.Add(UserData.Create(int.Parse(item[0]), item[1], item[3], item[4]));
                var count = 0;
                foreach (var uc in UserCredential.CreateCredential(item[1], item[2], item[4], int.Parse(item[0])))
                {
                    Console.WriteLine("id: {0}, value: {1}",uc._id, uc.Value);
                    if (count == 0)
                    {
                        userCredential.Add(uc);

                    }
                    else if (count == 1)
                    {
                        userCredential2.Add(uc);

                    }
                    count++;
                }

            }
            dic["ULC_L_201402"] = userCredential;
            dic["ULC_E_201402"] = userCredential2;
            return Tuple.Create<Dictionary<string, IEnumerable<UserCredential>>, IEnumerable<UserData>>(dic, userList);
        }
    }
}
